package o;

import android.util.Log;
import java.lang.reflect.Constructor;

public class fiq {
    private static fit ˏ = new fit();

    public static <T> T ˎ(fhw o_fhw) {
        return ˏ(ˏ, o_fhw);
    }

    public static <T> T ˏ(fit o_fit, fhw o_fhw) {
        if (o_fhw != null) {
            try {
                if (!o_fhw.ˏ()) {
                    return o_fhw.ˎ().newInstance();
                }
                T ˎ;
                synchronized (fiq.class) {
                    ˎ = o_fit.ˎ(o_fhw.ˎ());
                    if (ˎ == null) {
                        ˎ = o_fhw.ˎ().newInstance();
                        o_fit.ˏ(o_fhw.ˎ(), ˎ);
                    }
                }
                return ˎ;
            } catch (Exception e) {
                Log.e("ApiFactory", "create failed:" + e.getMessage());
            }
        }
        return null;
    }

    public static <T> T ˊ(fit o_fit, fhw o_fhw, Object... objArr) {
        if (objArr.length == 0) {
            return ˏ(o_fit, o_fhw);
        }
        if (o_fhw != null) {
            try {
                if (!o_fhw.ˏ()) {
                    return ˎ(o_fhw.ˎ(), objArr).newInstance(objArr);
                }
                T ˎ;
                synchronized (fiq.class) {
                    ˎ = o_fit.ˎ(o_fhw.ˎ());
                    if (ˎ == null) {
                        ˎ = ˎ(o_fhw.ˎ(), objArr).newInstance(objArr);
                        o_fit.ˏ(o_fhw.ˎ(), ˎ);
                    }
                }
                return ˎ;
            } catch (Exception e) {
                Log.e("ApiFactory", "create failed with arguments:" + e.getMessage());
            }
        }
        return null;
    }

    private static Constructor ˎ(Class cls, Object... objArr) {
        Constructor[] declaredConstructors = cls.getDeclaredConstructors();
        int length = declaredConstructors.length;
        int i = 0;
        boolean z = false;
        while (i < length) {
            boolean z2;
            Constructor constructor = declaredConstructors[i];
            Class[] parameterTypes = constructor.getParameterTypes();
            if (parameterTypes.length == objArr.length) {
                z2 = z;
                for (int i2 = 0; i2 < objArr.length; i2++) {
                    z2 = parameterTypes[i2].isAssignableFrom(objArr[i2].getClass());
                }
                if (z2) {
                    return constructor;
                }
            } else {
                z2 = z;
            }
            i++;
            z = z2;
        }
        throw new IllegalStateException("Do not match constructor with argument number: " + objArr.length);
    }
}
